package kr.nextree.edu.data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import kr.nextree.edu.domain.WordBook;

public class WordBookData {

	private static WordBookData wordBookData;

	private Map<Integer, WordBook> bookDatas;

	public static WordBookData getBookInstance() {
		if (wordBookData == null) {
			wordBookData = new WordBookData();
		}
		return wordBookData;
	}

	public void putWordBook(WordBook wordBook) {
		if (bookDatas == null) {
			bookDatas = new HashMap<Integer, WordBook>();
		}
		if (wordBook == null)
			return;

		bookDatas.put(wordBook.getId(), wordBook);
	}

	public List<WordBook> getWorddBooks() {
		if (bookDatas == null)
			return Collections.emptyList();

		List<WordBook> books = new ArrayList<WordBook>();

		Iterator<Integer> iter = bookDatas.keySet().iterator();
		while (iter.hasNext()) {
			books.add(bookDatas.get(iter.next()));
		}
		return books;

	}

	public int getMaximunKey() {
		if (bookDatas == null)
			return 1;

		return bookDatas.size() + 1;
	}

}
